package com.rtx.wms.std.validation.so;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.stereotype.Component;

import com.rtx.api.annotation.DataSourceAnnotation;
import com.rtx.wms.std.common.bean.Codelkup;
import com.rtx.wms.std.common.bean.WmsConstant;
import com.rtx.wms.std.erpconfig.bean.RtxErpConfig;
import com.rtx.wms.std.sku.bean.po.Sku;
import com.rtx.wms.std.so.bean.ApiOrderdetail;
import com.rtx.wms.std.so.bean.ApiOrders;
import com.rtx.wms.std.validation.BaseValidation;

/**
 * 出库单验证
 */
@Component
public class OrdersValidation extends BaseValidation {

	/**
	 * 校验企业级数据
	 */
	@DataSourceAnnotation
	public void  checkEnterpriseConfig(String datasourekey,ApiOrders o) {
		Set<String> whseidSet = new HashSet<>();
		
		//校验单据类型转换
		Codelkup typeConfig = validationCodelkup(WmsConstant.ENTERPRISE,o.getType(),"ORDERTYPE",true);
		o.setTypeConfig(typeConfig);
		
		for(ApiOrderdetail od:o.getDetails()) {
			List<RtxErpConfig> configList =	validationErpConfig(WmsConstant.ENTERPRISE, od.getLottable01(), od.getLottable02());
			od.setWhseid(configList.get(0).getWmwhse());
			whseidSet.add(configList.get(0).getWmwhse());
			o.setWhseid(configList.get(0).getWmwhse());
			
			Sku sku = validationSku(WmsConstant.ENTERPRISE, od.getStorerkey(), od.getSku(), true);
			od.setSkuentity(sku);
		}
		
		
		
		if(whseidSet.size()>1) {
			throw new RuntimeException("明细中工厂库存地在工厂库存地中只能wms一个仓库");
		}
		
	}
}
